<template>
	<div class="jcxx">
		<el-card class="box-card">
			<div slot="header" class="clearfix">
				<span>基础信息</span>
			</div>
			<div class="text item">
				<el-row :gutter="15">
					<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="100px">
						<el-row :gutter="180">
							<el-col :span="12">
								<el-form-item label="盘点单号" prop="warehouseCode">
									<el-input v-model="form.checkCode" placeholder="盘点自动获取" clearable
										:style="{width: '100%'}" disabled></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="盘点类型" prop="checkType">
									<el-select v-if="dict.type.py_stocktaking_type.length > 0" v-model="form.checkType"
										placeholder="请选择盘点类型" clearable :style="{ width: '100%' }">
										<el-option v-for="dict in dictOptions" :key="dict.value" :label="dict.label"
											:value="dict.value" />
									</el-select>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row :gutter="180">
							<el-col :span="12">
								<el-form-item label="开始时间" prop="checkStarttime">
									<el-date-picker v-model="form.checkStarttime" format="yyyy-MM-dd"
										value-format="yyyy-MM-dd" :style="{ width: '100%' }" placeholder="请选择">
									</el-date-picker>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="结束时间" prop="checkEndtime">
									<el-date-picker clearable v-model="form.checkEndtime" type="date"
										value-format="yyyy-MM-dd" placeholder="请选择结束时间">
									</el-date-picker>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row :gutter="180">
							<el-col :span="12">
								<el-form-item label="仓库名称" prop="warehouseName">
									<el-select v-model="form.warehouseName" filterable placeholder="请输入仓库名称"
										@change="changeWarehouse()" :style="{ width: '100%' }">
										<el-option v-for="item in warehouseOptions" :key="item.value"
											:label="item.lable" :value="item.lable">
										</el-option>
									</el-select>
								</el-form-item>

							</el-col>
							<el-col :span="12">
								<el-form-item label="经办人" prop="handledBy">
									<el-input v-model="form.handledBy" placeholder="请输入经办人" />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24">
								<el-form-item label="备注" prop="checkRemark">
									<el-input type="textarea" rows="5" v-model="form.checkRemark" placeholder="请输入" />
								</el-form-item>
							</el-col>
						</el-row>



						<el-footer class="fixed-footer">
							<el-button @click="ocClude">关闭</el-button>
							<el-button @click="draftForm">保存为草稿</el-button>
							<el-button type="primary" @click="submitForm">保存</el-button>
						</el-footer>


					</el-form>
				</el-row>
			</div>
		</el-card>
		<el-card class="box-card">
			<div slot="header" class="clearfix">
				<span>盘点明细</span>
			</div>
			<div class="text item">
				<el-row :gutter="15">
					<el-col :span="24" style="margin: 20px 0px;">
						<div>
							<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">添加</el-button>
							<el-button type="danger" icon="el-icon-delete" size="mini" @click="removeCheck">删除
							</el-button>
							<!-- <el-button type="primary" @click="handleAdd">新增</el-button>
							<el-button type="danger" plain icon="el-icon-delete" @click="removeCheck">移除 -->
							</el-button>
						</div>
					</el-col>
				</el-row>

				<el-row :gutter="15">
					<el-col :span="24">
						<el-table
							:height="(check.tableCheck.length > 4) ? '340px': check.tableCheck.length == 0 ?'112px': check.tableCheck.length * 57 + 55 + 'px'"
							:data="check.tableCheck" @selection-change="handleSelectionChangecheck"
							:default-sort="{prop: 'inventoryQueryId', order: 'ascending'}">
							<el-table-column type="selection" width="50" align="center" />
							<el-table-column align="center" prop="inventoryQueryId" label="序号" width="80" sortable
								fixed />
							<el-table-column align="center" prop="product.productName" label="货品名称" width="110" fixed />
							<el-table-column align="center" prop="product.productCode" label="货品编号" width="155" fixed />
							<el-table-column align="center" prop="product.productModel" label="规格型号" width="110" />
							<el-table-column align="center" prop="currentInventory" label="账面库存" width="110" />
							<el-table-column align="center" prop="inventoryValue" label="账面金额" width="110" />
							<el-table-column align="center" prop="bsWhLocation.locationName" label="盘点库位" width="110" />
							<el-table-column align="center" width="110">
								<template slot="header" slot-scope='scope'>
									<p><span style="color: red;">*</span>盘点数量</p>
								</template>
								<template slot-scope="scope">
									<el-input v-model="scope.row.detailsNumber" @change="changeNumber(scope.row)">
									</el-input>
								</template>
							</el-table-column>
							<el-table-column align="center" prop="detailsLossNumber" label="盈亏数量" width="110">
								<template slot-scope="scope">
									<span v-if="scope.row.detailsLossNumber > 0"
										style="color: green">{{ scope.row.detailsLossNumber }}</span>
									<span v-else-if="scope.row.detailsLossNumber < 0"
										style="color: red">{{ scope.row.detailsLossNumber }}</span>
									<span v-else>{{ scope.row.detailsLossNumber }}</span>
								</template>
							</el-table-column>
							<el-table-column align="center" prop="detailsStatus" label="盘点状态" width="110">
								<template slot-scope="scope">
									<dict-tag :options="dict.type.py_stocktaking_status"
										:value="scope.row.detailsStatus" />
								</template>
							</el-table-column>
							</el-table-column>
							<el-table-column align="center" prop="inventoryValue" label="参考单价" width="110">
								<template slot-scope="scope">
									<el-input v-model="scope.row.inventoryValue" @change="changeValue(scope.row)">
									</el-input>
								</template>
							</el-table-column>
							<el-table-column align="center" prop="detailsMoney" label="盈亏金额" width="110" />
							<el-table-column align="center" prop="detailsRemark" label="备注" width="170">
								<template slot-scope="scope">
									<el-input v-model="scope.row.detailsRemark"></el-input>
								</template>
							</el-table-column>
							<el-table-column align="center" fixed="right" label="操作" width="60">
								<template slot-scope="scope">
									<el-button type="text" size="small" @click="removeCheck(scope.row)">移除</el-button>
								</template>
							</el-table-column>
						</el-table>
						<div style="margin-top: 15px;font-size: 12px;">
							<div style="float: left;">合计</div>
							<div style="float: left;"></div>
							<div style="float: right;">盘亏金额：<span
									style="color:orange;margin-right: 20px;">{{form.noInventoryPrice}}</span></div>
							<div style="float: right;">盘盈金额：<span
									style="color:orange;margin-right: 20px;">{{form.yesInventoryPrice}}</span></div>
							<div style="float: right;">盘亏数量：<span
									style="color:orange;margin-right: 20px;">{{form.noInventoryNumber}}</span></div>
							<div style="float: right;">盘盈数量：<span
									style="color:orange;margin-right: 20px;">{{form.yesInventoryNumber}}</span></div>
							<div style="float: right;">盘点数量：<span
									style="color:orange;margin-right: 20px;">{{form.checkNumber}}</span></div>
							<div style="float: right;">账面金额：<span
									style="color:orange;margin-right: 20px;">{{form.bookPrice}}</span></div>
							<div style="float: right;">账面库存：<span
									style="color:orange;margin-right: 20px;">{{form.bookInventory}}</span></div>
						</div>
					</el-col>
				</el-row>
			</div>
		</el-card>

		<el-card class="box-card">
			<div slot="header" class="clearfix">
				<span>上传附件</span>
			</div>
			<div class="text item">
				<el-upload class="upload-demo" :action="uploadImgUrl" :on-change="uploadChange" :file-list="fileList"
					:before-upload="beforeUpload" :headers="headers" :before-remove="beforeRemove"
					:on-remove="handleRemove">
					<el-button size="small" type="primary">上传</el-button>
					<div slot="tip" class="el-upload__tip">您可以上传doc, pdf, rar等格式的文件，单个文件上传最大200MB。</div>
				</el-upload>
			</div>
		</el-card>

		<el-dialog :title="'添加货品'" :visible.sync="open" width="900px" append-to-body>
			<el-divider></el-divider>
			<el-row :gutter="50">
				<el-col :span="18">
					<el-form :model="queryParams" ref="queryForm" size="small" :inline="true"
						v-show="product.showSearch" label-width="68px">
						<el-form-item prop="productName">
							<el-input v-model="queryParams.productName" placeholder="请输入货品名称" clearable
								@keyup.enter.native="handleQuery" />
						</el-form-item>
						<el-form-item prop="productUnit">
							<el-select v-model="queryParams.productUnit" placeholder="请选择单位" clearable>
								<el-option v-for="dict in dict.type.py_product_unit" :key="dict.value"
									:label="dict.label" :value="dict.value" />
							</el-select>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="6">
					<el-button size="small">重置</el-button>
					<el-button type="success" size="small" @click="handleQuery">搜索</el-button>
				</el-col>
			</el-row>

			<el-table v-loading="product.productLoading" :data="product.tableProduct" style="width: 100%"
				@selection-change="handleSelectionChange"
				:default-sort="{prop: 'inventoryQueryId', order: 'ascending'}">
				<el-table-column type="selection" width="50" align="center" />
				<el-table-column align="center" prop="inventoryQueryId" label="序号" width="110" sortable />
				<el-table-column align="center" prop="product.productCode" label="货品编号" />
				<el-table-column align="center" prop="product.productName" label="货品名称" width="110" />
				<el-table-column align="center" prop="product.productModel" label="规格型号" width="110" />
				<el-table-column label="单位" align="center" prop="product.product.productUnit" width="100">
					<template slot-scope="scope">
						<dict-tag :options="dict.type.py_product_unit" :value="scope.row.product.productUnit" />
					</template>
				</el-table-column>
				<el-table-column align="center" prop="product.inboundPrice" label="入库单价" width="110" />
				<el-table-column align="center" prop="currentInventory" label="当前库存" width="110" />
			</el-table>

			<pagination v-show="product.productTotal>0" :total="product.productTotal" :page.sync="queryParams.pageNum"
				:limit.sync="queryParams.pageSize" @pagination="getListProduct" />
			<el-divider></el-divider>
			<span slot="footer" class="dialog-footer">
				<el-button @click="open = false">取 消</el-button>
				<el-button type="primary" @click="submitDialog">确 定</el-button>
			</span>

		</el-dialog>



		<div style="margin-top: 50px;">1</div>
	</div>

</template>
<script>
	import {
		addCheck,
		updateCheck,
		listProduct,
		getCheck,
		getCode,
	} from "@/api/check/check";

	import {
		addDetails,
		updateDetails,
	} from "@/api/check/details";

	import {
		getToken
	} from "@/utils/auth";

	import {
		listWarehouse //获取仓库名
	} from "@/api/warehouse/warehouse"

	export default {
		name: "Check",
		dicts: ['py_stocktaking_type', 'py_stocktaking_result', 'py_product_unit', 'py_stocktaking_status'],
		data() {
			return {
				// 表单参数
				form: {
					checkId: null,
					checkCode: null,
					checkResult: null,
					warehouseName: null,
					checkType: null,
					checkStarttime: null,
					checkEndtime: null,
					handledBy: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					isDelete: null,
					checkRemark: null,
					codeId: 'PDBH20200101',
					number: '1',
					fileList: [],
					bookInventory: 0, //账面库存
					bookPrice: 0, //账面金额
					checkNumber: 0, //盘点数量
					yesInventoryNumber: 0, //盘盈数量
					noInventoryNumber: 0, //盘亏数量
					yesInventoryPrice: 0, //盘盈金额
					noInventoryPrice: 0, //盘亏金额
				},
				//仓库名
				warehouseOptions: [],
				//表单验证
				rules: {
					checkCode: [{
						required: true,
						message: "盘点编号不能为空",
						trigger: "blur"
					}],
					checkStarttime: [{
						required: true,
						message: "盘点开始时间不能为空",
						trigger: "blur"
					}],
					checkEndtime: [{
						required: true,
						message: "盘点结束不能为空",
						trigger: "blur"
					}],
					warehouseName: [{
						required: true,
						message: "仓库名称不能为空",
						trigger: "blur"
					}],
				},
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					productName: null,
					productUnit: null,
					warehouseCode: null,
				},
				// 是否显示弹出层
				open: false,
				product: {
					productCodes: [], //选中的库存商品
					showSearch: true, //显示搜索条件
					productTotal: 0, // 库存商品总条数
					productLoading: true, //库存商品遮罩层
					tableProduct: [], //商品参数
				},
				check: {
					tableCheck: [], //盘点详细
					productCodes: [], //选中的盘点商品
				},
				uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload",
				headers: {
					Authorization: "Bearer " + getToken()
				},
				fileList: [], // 已上传的文件列表
				checkId: null, //如果不为空则编辑
				dictOptions: [{
						value: 0,
						label: '初期盘点'
					},
					{
						value: 1,
						label: '库存盘点'
					},
					{
						value: 2,
						label: '期末盘点'
					},
				],
				isClick: true,
			}
		},
		computed: {

		},
		watch: {},
		created() {
			this.checkId = this.$route.query.checkId;
			this.isEdit();
		},
		mounted() {},
		watch: {
			open(newValue, oldValue) {
				if (newValue == false) {
					this.queryParams.productName = null;
					this.queryParams.productUnit = null;
					this.queryParams.pageNum = 1;
					this.queryParams.pageSize = 10;
				}
			}
		},
		methods: {
			//判断是否是修改
			isEdit() {
				if (this.checkId != null) {
					getCheck(this.checkId).then(response => {

						this.form = response.data;
						console.log(this.form)
						// 合并新旧文件列表
						this.fileList = [...this.form.pyAttachments.flat().map(file => ({
							name: file.fileName,
							url: file.filePath,
							size: file.size
						})), ...this.fileList];

						listWarehouse().then((response) => {
							response.rows.forEach(item => {
								this.warehouseOptions.push({
									'lable': item.warehouseName,
									'value': item.warehouseCode,
									'lock': item.warehouseLock,
								})
							})

							this.warehouseOptions.forEach(item => {
								if (item.lable == this.form.warehouseName) {
									this.queryParams.warehouseCode = item.value;
								}
							})
							if (this.queryParams.warehouseCode == null) {
								return;
							}
							this.product.productLoading = true;
							listProduct(this.queryParams).then(response => {
								this.product.tableProduct = response.rows;
								this.product.productTotal = response.total;
								this.product.productLoading = false;
								this.product.tableProduct.forEach(item => {
									this.$set(item, 'detailsNumber', null);
									this.$set(item, 'detailsLossNumber', 0);
									this.$set(item, 'detailsStatus', 0);
									this.$set(item, 'detailsMoney', 0);
									this.$set(item, 'detailsRemark', null);
								})

								this.check.tableCheck.forEach(check => {
									this.product.tableProduct = this.product.tableProduct
										.filter(item => item
											.inventoryQueryId != check.inventoryQueryId);
									this.product.productTotal -= 1;
								})


								this.product.productCodes = this.form.whCheckDetails.map(item =>
									item.productCode);


								this.product.productCodes.forEach(i => {
									// 假设我们要移动 id 为 1 的项目
									const itemToMove = this.product.tableProduct.find(
										item => item.productCode === i);
									this.product.productTotal -= 1;
									if (itemToMove) {
										const index = this.product.tableProduct.indexOf(
											itemToMove);
										if (index > -1) {
											this.product.tableProduct.splice(index,
												1); // 从 array1 移除
											this.check.tableCheck.push(
												itemToMove); // 添加到 array2
										}
									}
								})

								this.check.tableCheck.forEach(check => {
									this.form.whCheckDetails.forEach(details => {
										if (check.inventoryQueryId == details
											.inventoryQueryId) {
											this.$set(check, 'detailsNumber',
												details.detailsNumber);
											this.$set(check, 'detailsLossNumber',
												details.detailsLossNumber);
											this.$set(check, 'detailsStatus',
												details.detailsStatus);
											this.$set(check, 'detailsMoney',
												details.detailsMoney);
											this.$set(check, 'detailsRemark',
												details.detailsRemark);
										}
									})
								})


							});

						})


					})
				} else {
					this.initName();
					getCode(4).then(response => {
						this.form.checkCode = response.sequence;
						this.form.number = response.number;
						this.form.codeId = response.codeId;
					})
				}
			},

			//删除文件之后
			handleRemove(file, fileList) {
				this.fileList = fileList;
			},
			//删除文件之前
			beforeRemove(file, fileList) {
				return this.$confirm(`确定移除 ${ file.name }？`);
			},
			//上传文件
			uploadChange(file, fileList) {
				this.fileList = fileList;
			},
			beforeUpload(file) {
				// 定义允许的文件类型
				const allowedTypes = ['application/msword', 'application/pdf', 'application/x-rar-compressed',
					'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
				];
				// 检查文件类型是否在允许的类型中
				const isAllowedType = allowedTypes.includes(file.type);
				// 检查文件大小是否不超过200MB (200 * 1024 * 1024 bytes)
				const isLt200M = file.size <= 200 * 1024 * 1024;

				if (!isAllowedType) {
					this.$message.error('上传文件只能是 doc, pdf, rar 格式!');
				}
				if (!isLt200M) {
					this.$message.error('上传文件大小不能超过 200MB!');
				}
				return isAllowedType && isLt200M;
			},
			// 移除
			removeCheck(row) {
				var inventoryQueryIds = row.inventoryQueryId || this.check.productCodes.map(item => item.inventoryQueryId)
				var array = Array.isArray(inventoryQueryIds) ? inventoryQueryIds : [inventoryQueryIds];
				this.$modal.confirm('是否确认删除编号为"' + array + '"的数据项？').then(() => {
					array.forEach(i => {
						const itemToMove = this.check.tableCheck.find(item => item.inventoryQueryId === i);
						this.product.productTotal += 1;
						if (itemToMove) {
							itemToMove.detailsNumber = null;
							const index = this.check.tableCheck.indexOf(itemToMove);
							if (index > -1) {
								this.check.tableCheck.splice(index, 1); // 从 array1 移除
								this.product.tableProduct.push(itemToMove); // 添加到 array2
							}
						}
					});

					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},

			// 改变盘点数量
			changeNumber(row) {
				if (row.detailsNumber === '')
					row.detailsNumber = 0;
				row.detailsLossNumber = row.detailsNumber - row.currentInventory;
				row.detailsMoney = row.detailsLossNumber * row.inventoryValue;
				if (row.currentInventory < row.detailsNumber)
					row.detailsStatus = 1;
				else if (row.currentInventory > row.detailsNumber)
					row.detailsStatus = 2;
				else
					row.detailsStatus = 0;

				this.check.productCodes.forEach((item, index) => {
					if (item.inventoryQueryId === row.inventoryQueryId) {
						this.$set(this.check.productCodes, index, row);
					}
				});
				this.calculateTotal();
			},

			// 改变单价
			changeValue(row) {
				row.detailsMoney = row.detailsLossNumber * row.inventoryValue;
				this.check.productCodes.forEach((item, index) => {
					if (item.inventoryQueryId === row.inventoryQueryId) {
						this.$set(this.check.productCodes, index, row);
					}
				});
				this.calculateTotal();
			},

			// 搜索库存
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getListProduct();
			},

			// 添加盘点详细
			submitDialog() {
				this.open = false;
				this.product.productCodes.forEach(i => {
					// 假设我们要移动 id 为 1 的项目
					const itemToMove = this.product.tableProduct.find(item => item.productCode === i);
					this.product.productTotal -= 1;
					if (itemToMove) {
						const index = this.product.tableProduct.indexOf(itemToMove);
						if (index > -1) {
							this.product.tableProduct.splice(index, 1); // 从 array1 移除
							this.check.tableCheck.push(itemToMove); // 添加到 array2
						}
					}
				})
			},

			// 库存商品多选框选中数据
			handleSelectionChange(selection) {
				this.product.productCodes = selection.map(item => item.productCode)
			},

			// 盘点商品多选框选中数据
			handleSelectionChangecheck(selection) {
				selection.forEach(item => {
					this.$set(item, 'checkCode', this.form.checkCode);
				})
				this.check.productCodes = selection;
				this.calculateTotal();
			},

			//计算合计
			calculateTotal() {
				this.form.bookInventory = this.check.productCodes.reduce((total, row) => total + row.currentInventory, 0);
				this.form.bookPrice = this.check.productCodes.reduce((total, row) => total + parseInt(row.inventoryValue),
					0);
				this.form.checkNumber = this.check.productCodes.filter(item => item.detailsNumber != null).reduce((total,
					row) => total + parseInt(row.detailsNumber), 0);
				this.form.yesInventoryNumber = this.check.productCodes.filter(item => item.detailsLossNumber > 0).reduce((
					total, row) => total + row.detailsLossNumber, 0);
				this.form.yesInventoryPrice = this.check.productCodes.filter(item => item.detailsLossNumber > 0).reduce((
					total, row) => total + row.detailsMoney, 0);
				this.form.noInventoryNumber = this.check.productCodes.filter(item => item.detailsLossNumber < 0).reduce((
					total, row) => total + row.detailsLossNumber, 0);
				this.form.noInventoryPrice = this.check.productCodes.filter(item => item.detailsLossNumber < 0).reduce((
					total, row) => total + row.detailsMoney, 0);
			},
			/** 查询库存商品列表 */
			getListProduct() {
				this.product.productLoading = true;
				listProduct(this.queryParams).then(response => {
					this.product.tableProduct = response.rows;
					this.product.productTotal = response.total;
					this.product.productLoading = false;
					this.product.tableProduct.forEach(item => {
						this.$set(item, 'detailsNumber', null);
						this.$set(item, 'detailsLossNumber', 0);
						this.$set(item, 'detailsStatus', 0);
						this.$set(item, 'detailsMoney', 0);
						this.$set(item, 'detailsRemark', null);
					})

					this.check.tableCheck.forEach(check => {
						this.product.tableProduct = this.product.tableProduct.filter(item => item
							.inventoryQueryId != check.inventoryQueryId);
						this.product.productTotal -= 1;
					})
				});
			},

			//重置盘点详细
			changeWarehouse() {
				this.warehouseOptions.forEach(item => {
					if (item.lable == this.form.warehouseName) {
						if (item.lock == 0) {
							this.$alert('名称为 [ ' + item.lable + ' ] 的仓库未锁定，请锁定之后再进行盘点。', '标题名称', {
								confirmButtonText: '确定',
								type: 'warning'
							});
							this.form.warehouseName = null;
						} else {
							this.restTable();
							this.queryParams.warehouseCode = item.value;
							this.getListProduct();
						}
					}
				})
			},

			//清空库存商品和盘点商品
			restTable() {
				this.product.productCodes = [];
				this.product.tableProduct = [];
				this.check.tableCheck = [];
				this.check.productCodes = [];
			},

			// 新增盘点明细
			handleAdd() {
				if (this.form.warehouseName != null)
					this.open = true;
				else
					this.$message({
						message: '请选择仓库！',
						type: 'warning'
					});
			},

			//获取仓库名
			initName() {
				listWarehouse().then((response) => {
					response.rows.forEach(item => {
						this.warehouseOptions.push({
							'lable': item.warehouseName,
							'value': item.warehouseCode,
							'lock': item.warehouseLock,
						})
					})
				})
			},
			//保存添加
			submitForm() {
				this.$refs["form"].validate(valid => {

					if (valid) {
						if (!this.isClick) {
							this.$message.warning('请勿重复提交');
							return;
						}
						this.isClick = false;
						if (this.check.productCodes.length === 0) {
							this.$message({
								message: '请选择盘点商品！',
								type: 'warning'
							});
							this.isClick = true;
							return;
						}
						const flag = this.check.productCodes.some(item => item.detailsNumber === null);
						if (flag) {
							this.$message({
								message: '盘点数量不能为空！',
								type: 'warning'
							});
							this.isClick = true;
							return;
						}
						this.form.checkResult = this.check.productCodes.some(item => item.detailsStatus != 0) ?
							1 : 0;
						//添加盘点单
						this.form.fileList = this.fileList;

						console.log(this.form.fileList)

						if (this.checkId != null) {
							updateCheck(this.form).then(response => {
								updateDetails(this.form.checkCode).then(response => {
									addDetails(this.check.productCodes);
								});
								this.$modal.msgSuccess("保存成功");
								this.$router.push({
									path: '/wms/check/check/index'
								});
							}).catch(error => {
								this.isClick = true;
							});

							return;
						}

						addCheck(this.form).then(response => {
							addDetails(this.check.productCodes);
							this.$modal.msgSuccess("保存成功");
							this.$router.push({
								path: '/wms/check/check/index'
							});
						}).catch(error => {
							this.isClick = true;
						});

						return;
					}
				});
			},

			//保存草稿
			draftForm() {
				if (!this.isClick) {
					this.$message.warning('请勿重复提交');
					return;
				}
				this.form.checkResult = 2;
				this.form.fileList = this.fileList;

				if (this.check.productCodes.length === 0) {
					this.$message({
						message: '请选择盘点商品！',
						type: 'warning'
					});
					this.isClick = true;
					return;
				}
				const flag = this.check.productCodes.some(item => item.detailsNumber === null);
				if (flag) {
					this.$message({
						message: '盘点数量不能为空！',
						type: 'warning'
					});
					this.isClick = true;
					return;
				}

				if (this.checkId != null) {
					updateCheck(this.form).then(response => {
						updateDetails(this.form.checkCode).then(response => {
							addDetails(this.check.productCodes);
						});
						this.$modal.msgSuccess("保存成功");
						this.$router.push({
							path: '/wms/check/check/index'
						});
					}).catch(error => {
						this.isClick = true;
					});

					return;
				}

				addCheck(this.form).then(response => {
					if (this.check.productCodes.length > 0) {
						addDetails(this.check.productCodes);
					}

					this.$modal.msgSuccess("保存成功");
					this.$router.push({
						path: '/wms/check/check/index'
					});
				}).catch(error => {
					this.isClick = true;
				});
			},
			//关闭
			ocClude() {
				// this.$router.push({
				// 	path: '/wms/check/check/index'
				// });

				const obj = {
					path: "/wms/check/check/index",
					query: {
						t: Date.now()
					}
				};
				this.$tab.closeOpenPage(obj);
			}

		},
	}
</script>
<style>
	.fixed-footer {
		position: fixed;
		bottom: 0;
		left: 100px;

		right: 0;
		padding-left: 1400px;
		padding-top: 20px;
		background-color: #f4f4f4;
		/* 设置底部背景色 */
		z-index: 1000;
		/* 确保底部不被遮挡 */
	}

	.jcxx {
		margin-top: 20px;

	}

	.text {
		font-size: 14px;
	}

	.item {
		margin-bottom: 18px;
	}

	.clearfix:before,
	.clearfix:after {
		display: table;
		content: "";
	}

	.clearfix:after {
		clear: both
	}

	.box-card {
		width: 100%;
		margin-top: 20px;
	}

	.total-row {
		background-color: #f9f9f9;
		/* 背景色 */
		font-weight: bold;
		/* 粗体 */
	}

	.label {
		color: black;
		/* 标签字体颜色 */
		margin-left: 10px;
	}

	.you {
		margin-left: 930px;
	}

	.value {
		color: rgb(227, 139, 50);
		/* 数字字体颜色 */
	}

	/* 如果需要调整对齐方式，可以添加其他样式 */
	.total-row td {
		text-align: left;
		/* 左对齐 */
	}

	.total-row td:last-child {
		text-align: right;
		/* 最后一列右对齐 */
	}

	.el-date-editor .el-input__inner {
		width: 516px;
	}

	/* 设置el-select的宽度为200px */
	.custom-select {
		width: 516px;
	}
</style>
